package com.guochuang.yunwang.promanager.controller;


import com.guochuang.yunwang.promanager.annotation.CancelLoginIntercept;
import com.guochuang.yunwang.promanager.domain.date;
import com.guochuang.yunwang.promanager.domain.progress;
import com.guochuang.yunwang.promanager.domain.vo.ProjectDetailVO;
import com.guochuang.yunwang.promanager.domain.vo.ProjectTimeLineVO;
import com.guochuang.yunwang.promanager.domain.vo.project.*;
import com.guochuang.yunwang.promanager.exception.ParamException;
import com.guochuang.yunwang.promanager.service.ProjectDetailService;
import com.guochuang.yunwang.promanager.utils.ProjectConstant;
import com.guochuang.yunwang.promanager.utils.ResultEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "项目详情页接口")
public class ProjectDetailController {

    @Autowired
    private ProjectDetailService projectDetailService;


    @GetMapping(value = "/get/project/time/line/{pid}")
    @ApiOperation(value = "获取项目时间线数据")
    @CancelLoginIntercept
    public ResultEntity selectProjectTimeData(@PathVariable Integer pid) {
        if (pid == null) {
            throw new ParamException(ProjectConstant.PARAM_ERROR_MESSAGE);
        }
        List<ProjectTimeLineVO> rec = projectDetailService.getProjectTimeLineData(pid);

        return ResultEntity.successWithData(rec);

    }

    @GetMapping(value = "/get/project/detail/info/{pid}")
    @ApiOperation(value = "根据项目id获取项目详情")
    @CancelLoginIntercept
    public ResultEntity selectProjectDetailInfo(@PathVariable Integer pid) {
        if (pid == null) {
            throw new ParamException(ProjectConstant.PARAM_ERROR_MESSAGE);
        }
        ProjectDetailVO rec = projectDetailService.getProjectDetailInfo(pid);

        return ResultEntity.successWithData(rec);
    }


    @GetMapping("/get/tasks")
    @ApiOperation("根据pid获取任务信息")
    public ResultEntity gettasks(@RequestParam Integer pid) {
        TasksVO gettaks = projectDetailService.gettaks(pid);
        return ResultEntity.successWithData(gettaks);
    }

    @GetMapping("get/requirements")
    @ApiOperation("根据pid获取需求信息")
    public ResultEntity getRequirements(@RequestParam Integer pid) {
        RequirementsVO requirements = projectDetailService.getRequirements(pid);
        return ResultEntity.successWithData(requirements);
    }

    @GetMapping("get/flaws/{pid}")
    @ApiOperation("根据pid获取缺陷信息")
    public ResultEntity getflaws(@PathVariable Integer pid) {
        FlawsVO getflaws = projectDetailService.getflaws(pid);
        return ResultEntity.successWithData(getflaws);
    }

    @GetMapping("get/act/{pid}")
    @ApiOperation("根据pid获取计划与实际信息")
    public ResultEntity getact(@PathVariable Integer pid) {
        ActVO getact = projectDetailService.getact(pid);
        return ResultEntity.successWithData(getact);
    }

    @GetMapping(value = "/get/project/progress/{pid}")
    @ApiOperation(value = "根据id获取项目进度数据")
    @CancelLoginIntercept
    public ResultEntity getProjectProgressInfo(@PathVariable Integer pid) {

        progress rec = projectDetailService.getProjectProgressinfo(pid);

        return ResultEntity.successWithData(rec);

    }

    @GetMapping(value = "/get/project/date/{id}")
    @ApiOperation(value = "根据id获取项目日期数据")
    @CancelLoginIntercept
    public ResultEntity getProjectDateInfo(@PathVariable Integer id) {

        date rec = projectDetailService.getProjectDateinfo(id);
        return ResultEntity.successWithData(rec);
    }
}

